using System;
using FU.Capstones.IMS.Web.Common;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.DataContracts;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.EventArgs;

namespace FU.Capstones.IMS.Web.Silverlight.Models
{
    public class MaterialListModel : ModelBase
    {
        public MaterialListModel()
        {
            client.DeleteMaterialCompleted += DoDeleteMaterialCompleted;
            client.UndoDeleteMaterialCompleted += DoUndoDeleteMaterialCompleted;
            client.GetMaterialCollectionCompleted += DoGetMaterialCollectionCompleted;
            client.GetSingleMaterialCompleted += DoGetSingleMaterialCompleted;
            client.SearchMaterialCompleted += DoSearchMaterialCompleted;
            client.GetWarehouseCollectionCompleted += DoGetWarehouseCollectionCompleted;
            client.GetPartnerCollectionByParamCompleted += DoGetPartnerCollectionCompleted;
            client.GetMaterialCollectionTypeCompleted += DoGetMaterialCollectionTypeCompleted;
        }

        #region GetPartnerCollection

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Partner>> GetPartnerCollectionCompleted;

        public int GetPartnerCollectionAsync()
        {
            client.GetPartnerCollectionByParamAsync(true);
            return WebConstants.MagicNumer;
        }

        private void DoGetPartnerCollectionCompleted(object sender, CollectionFeedbackCompletedEventArgs<Partner> e)
        {
            if (GetPartnerCollectionCompleted != null)
            {
                GetPartnerCollectionCompleted(sender, e);
            }
        }

        #endregion

        #region GetWarehouseCollection

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Warehouse>> GetWarehouseCollectionCompleted;

        public int GetWarehouseCollectionAsync()
        {
            client.GetWarehouseCollectionAsync(false);
            return WebConstants.MagicNumer;
        }

        private void DoGetWarehouseCollectionCompleted(object sender, CollectionFeedbackCompletedEventArgs<Warehouse> e)
        {
            if (GetWarehouseCollectionCompleted != null)
            {
                GetWarehouseCollectionCompleted(sender, e);
            }
        }

        #endregion
        
        #region SearchMaterial

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Material>> SearhMaterialCompleted;

        public int SearchMaterialAsync(MaterialCriteria criteria)
        {
            client.SearchMaterialAsync(criteria);
            return WebConstants.MagicNumer;
        }

        void DoSearchMaterialCompleted(object sender, CollectionFeedbackCompletedEventArgs<Material> e)
        {
            if (SearhMaterialCompleted != null)
            {
                SearhMaterialCompleted(sender, e);
            }
        }

        #endregion

        #region GetMaterialCollection

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Material>> GetMaterialCollectionCompleted;

        public int GetMaterialCollectionAsync(bool isShowAll)
        {
            client.GetMaterialCollectionAsync(isShowAll);
            return WebConstants.MagicNumer;
        }

        void DoGetMaterialCollectionCompleted(object sender, CollectionFeedbackCompletedEventArgs<Material> e)
        {
            if (GetMaterialCollectionCompleted != null)
            {
                GetMaterialCollectionCompleted(sender, e);
            }
        }

        #endregion

        #region GetMaterialCollectionType

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Material>> GetMaterialCollectionTypeCompleted;

        public int GetMaterialCollectionTypeAsync(bool isShowAll)
        {
            client.GetMaterialCollectionTypeAsync(isShowAll);
            return WebConstants.MagicNumer;
        }

        void DoGetMaterialCollectionTypeCompleted(object sender, CollectionFeedbackCompletedEventArgs<Material> e)
        {
            if (GetMaterialCollectionTypeCompleted != null)
            {
                GetMaterialCollectionTypeCompleted(sender, e);
            }
        }

        #endregion

        #region DeleteMaterial

        public event EventHandler<FeedbackCompletedEventArgs> DeleteMaterialCompleted;

        public int DeleteMaterialAsync(int data)
        {
            client.DeleteMaterialAsync(data);
            return WebConstants.MagicNumer;
        }

        void DoDeleteMaterialCompleted(object sender, FeedbackCompletedEventArgs e)
        {
            if (DeleteMaterialCompleted != null)
            {
                DeleteMaterialCompleted(sender, e);
            }
        }

        #endregion

        #region DeleteMaterial

        public event EventHandler<FeedbackCompletedEventArgs> UndoDeleteMaterialCompleted;

        public int UndoDeleteMaterialAsync(int data)
        {
            client.UndoDeleteMaterialAsync(data);
            return WebConstants.MagicNumer;
        }

        void DoUndoDeleteMaterialCompleted(object sender, FeedbackCompletedEventArgs e)
        {
            if (UndoDeleteMaterialCompleted != null)
            {
                UndoDeleteMaterialCompleted(sender, e);
            }
        }

        #endregion

        #region GetSingleMaterial

        public event EventHandler<SingleFeedbackCompletedEventArgs<Material>> GetSingleMaterialCompleted;

        public int GetSingleMaterialAsync(int objID)
        {
            client.GetSingleMaterialAsync(objID);
            return WebConstants.MagicNumer;
        }

        void DoGetSingleMaterialCompleted(object sender, SingleFeedbackCompletedEventArgs<Material> e)
        {
            if (GetSingleMaterialCompleted != null)
            {
                GetSingleMaterialCompleted(sender, e);
            }
        }

        #endregion
    }
}